//
//  LZSubTagCell.m
//  LZHundredJie
//
//  Created by apple on 16/4/5.
//  Copyright © 2016年 m14a.cn. All rights reserved.
//

#import "LZSubTagCell.h"
#import "LZSubTagItem.h"
#import "UIImageView+WebCache.h"

@interface LZSubTagCell ()
/** 存放图标的iconView*/
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
/** 主题名称*/
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
/** 订阅人数标签*/
@property (weak, nonatomic) IBOutlet UILabel *numLabel;

@end

@implementation LZSubTagCell


- (void)setItem:(LZSubTagItem *)item
{
    _item = item;
    // 1.设置图片
    // 头像
    UIImage *placeholder = [UIImage lz_circleImageNamed:@"defaultUserIcon"];
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:placeholder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        if (image == nil) {
            return ;
        }
        // 获取圆形图片
        UIImage *newImage = [image circleImage];
        self.iconView.image = newImage;
        
    }];
    // 2.设置姓名
    self.nameLabel.text = item.theme_name;
    // 3.订阅数量
    NSString *numStr = [NSString stringWithFormat:@"%@人订阅", item.sub_number];
    
    // 转数字
    int num = [numStr intValue];
    if (num > 10000) {
        CGFloat numF = num / 10000.0;
        numStr = [NSString stringWithFormat:@"%.1f万人订阅", numF];
        numStr = [numStr stringByReplacingOccurrencesOfString:@".0" withString:@""];
    }
    
    self.numLabel.text = numStr;
}

// 设置尺寸
- (void)setFrame:(CGRect)frame
{
    frame.origin.x = 5;
    frame.size.width -= 2 * frame.origin.x;
    
    frame.size.height -= 2;
    // 给cellframe赋值
    [super setFrame:frame];
}

@end
